using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Diagnostics;

namespace SJBotGame.SJBotGameComponentsDraw
{
    public class SJBotTitleHighlightDraw
    {
        private SJBotTitleDraw titleDraw;
        public SJBotTitleDraw TitleDraw { get { return titleDraw; } }
        //
        private int lastBlinkStatus;
        private Stopwatch blinkTimer = new Stopwatch();
        private double lastBlinkTimer;

        private const double timeOut = 200;
        private const int statusMax = 8;
        //
        public SJBotTitleHighlightDraw()
        {
            this.titleDraw = null;
        }
        //
        public void StartHighlight(SJBotTitleDraw titleDraw)
        {
            this.titleDraw = titleDraw;
            //
            lastBlinkStatus = 0;
            lastBlinkTimer = 0.00;
            blinkTimer.Start();
        }
        //
        private void IncStatus()
        {
            lastBlinkStatus++;
            if (lastBlinkStatus > statusMax) lastBlinkStatus = 0;
        }
        public void Update()
        {
            if (titleDraw == null) return;
            if ((lastBlinkTimer + timeOut) < blinkTimer.ElapsedMilliseconds)
            {
                lastBlinkTimer = blinkTimer.ElapsedMilliseconds;
                IncStatus();
            }
        }
        public void Redraw(Graphics formGraphics)
        {
            if (titleDraw == null) return;
            Rectangle rect = titleDraw.Rect;
            Color selectedColor = Color.FromArgb(Color.Silver.R - 24 * lastBlinkStatus, Color.Silver.G - 24 * lastBlinkStatus, Color.Silver.B - 24 * lastBlinkStatus);
            SolidBrush selectedBrush = new SolidBrush(selectedColor);
            formGraphics.FillRectangle(selectedBrush, rect);
            selectedBrush.Dispose();
        }
        //

    }
}
